using System;
using System.Text;

namespace Kontakter
{
    public static class Utils
    {
        public static string RemoveStringFormatting(string s)
        {
            StringBuilder str = new StringBuilder(s);
            int ind = 0;
            bool erase = false;
            while (ind < str.Length)
            {
                if (str[ind] == '&')
                    erase = true;
                else if (str[ind] == ';')
                    erase = false;

                if (erase || str[ind] == ';')
                    str.Remove(ind, 1);
                else
                    ind++;
            }

            return str.ToString();
        }

        public static string RemovePrecedingSpaces(string s)
        {
            StringBuilder str = new StringBuilder(s);
            while (str.Length != 0)
            {
                if (str[0] == ' ' || str[0] == '\n')
                    str.Remove(0, 1);
                else
                    break;
            }
            return str.ToString();
        }

        public static string RemoveSucceedingSpaces(string s)
        {
            StringBuilder str = new StringBuilder(s);
            while (str.Length != 0)
            {
                int last = str.Length - 1;
                if (str[last] == ' ' || str[last] == '\n')
                    str.Remove(last, 1);
                else
                    break;
            }
            return str.ToString();
        }
    }
}